import 'package:fluent_ui/fluent_ui.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get_navigation/src/root/get_material_app.dart';
import 'package:get/get_navigation/src/routes/transitions_type.dart';
import 'package:music_together/base/pageWidget/common_stateful_widget.dart';
import 'package:music_together/http/interceptor/netease_handler.dart';
import 'package:music_together/route/routes.dart';
import 'package:music_together/utils/injection.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'business/page/main/main_binding.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await initSDK();
  runApp(MyApp());
}

Future<void> initSDK() async {
  await NeteaseMusicApi.init(debug: true);
  await Injection().init();
}

class MyApp extends CommonStatefulWidget {
  @override
  State<StatefulWidget> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return RefreshConfiguration(
      footerTriggerDistance: 15,
      dragSpeedRatio: 0.91,
      headerBuilder: () => const ClassicHeader(),
      footerBuilder: () => const ClassicFooter(),
      enableLoadingWhenNoData: false,
      enableRefreshVibrate: false,
      enableLoadMoreVibrate: false,
      shouldFooterFollowWhenNotFull: (state) {
        // If you want load more with noMoreData state ,may be you should return false
        return false;
      },
      child: ScreenUtilInit(
          designSize: const Size(1440, 1024),
          builder: (context, __) =>
              AnimatedFluentTheme(data: FluentThemeData(), child: GetMaterialApp(
                localizationsDelegates: const [
                  DefaultMaterialLocalizations.delegate
                ],
                getPages: AppRoutes.routerPages,
                defaultTransition: Transition.rightToLeft,
                transitionDuration: const Duration(milliseconds: 150),
                // title: '一起听音乐',
                // theme: ThemeData(
                //   primarySwatch: Colors.red,
                // ),
                initialBinding: MainBinding(),
                // home: const MainPage(),
                initialRoute: AppRoutes.mainPage,
                locale: const Locale('zh'),
                // builder: (BuildContext context, Widget? child) {
                //
                // },
              ))


      ),
    );
  }
}
